package com.lvy.hczn.front.business.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lvy.hczn.front.business.common.Constants;
import com.lvy.hczn.front.business.mapper.PurchaseOrderMapper;
import com.lvy.hczn.front.system.domain.business.DataException;
import com.lvy.hczn.front.system.domain.business.DataExceptionDetail;
import com.lvy.hczn.front.system.domain.business.PurchaseOrder;
import com.lvy.hczn.front.system.domain.business.PurchaseOrderDetail;
import com.lvy.hczn.front.business.mapper.PurchaseOrderDetailMapper;
import com.lvy.hczn.front.business.service.PurchaseOrderDetailService;
import com.lvy.hczn.front.common.exception.UtilException;
import com.lvy.hczn.front.system.mapper.DataExceptionDetailMapper;
import com.lvy.hczn.front.system.mapper.DataExceptionMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class PurchaseOrderDetailServiceImpl extends ServiceImpl<PurchaseOrderDetailMapper, PurchaseOrderDetail> implements PurchaseOrderDetailService {

    @Autowired
    private PurchaseOrderDetailMapper purchaseOrderDetailMapper;

    @Autowired
    private PurchaseOrderMapper purchaseOrderMapper;

    @Autowired
    private DataExceptionMapper dataExceptionMapper;

    @Autowired
    private DataExceptionDetailMapper dataExceptionDetailMapper;

    /**
     * 根据采购单及状态查询
     *
     * @param purchaseCodes
     * @param status
     * @return
     * @author yw
     * @date 2022-07-13 16:06:54
     */
    @Override
    public List<PurchaseOrderDetail> selectByPurchase(List<String> purchaseCodes, String status, Integer temperatureCode) throws Exception {
        if (purchaseCodes == null || purchaseCodes.isEmpty()) {
            throw new UtilException("无采购单信息");
        }
        if (StrUtil.isEmpty(status)) {
            throw new UtilException("状态为空");
        }
        return purchaseOrderDetailMapper.selectByPurchase(purchaseCodes, status, temperatureCode);
    }

    @Override
    public List<PurchaseOrderDetail> selectByBoxCode(String boxCode, String status, Integer temperatureCode){
        if (StrUtil.isEmpty(status)) {
            throw new UtilException("状态为空");
        }
        return purchaseOrderDetailMapper.selectByBoxCode(boxCode, status, temperatureCode);
    }
}
